package ast;

public class JumpStatement extends Statement {
	// JumpStatement
	// BREAK_STMT, CONTINUE_STMT, RETURN_STMT,
	
	// 仅仅是返回语句需要填（Expression类）
	public AstItem return_data;

	public String toString() {
		if (type == StatementType.BREAK_STMT) return "break;";
		else if (type == StatementType.CONTINUE_STMT) return "continue;";
		else {
			assert type == StatementType.RETURN_STMT;
			if (return_data == null) return "return;";
			else return "return " + return_data.toString() + ";";
		}
	}
	
	public void preprocess(AstItem father) {
		if (return_data != null) return_data.preprocess(this);
	}

	@Override
	public String toJsonString() {
		String json = "{";
		json += "\"Type\": \"Statement-" + type.toString() + "\",";
		json += "\"Return_Data\": " + (return_data != null ? return_data.toJsonString() : "\"\"");
		json += "}";
		return json;
	}
}
